home *** CD-ROM | disk | FTP | other *** search
/ Language/OS - Multiplatform Resource Library / LANGUAGE OS.iso / oper_sys / emerald / emrldsys.lha / Language / Compiler / debuginfo.c < prev    next >
C/C++ Source or Header  |  1990-08-16  |  4KB  |  181 lines

  1. #include "assert.h"
  2. #include "trace.h"
  3. #include "symbols.h"
  4. #include "allocate.h"
  5.  
  6. typedef enum { DISymbol, DIStart, DIEnd, DIVector } DITag;
  7. #define StackDepth() (sstack ? sstack->depth : 1)
  8.  
  9. typedef struct sSymbolInfo {
  10.   DITag             tag;
  11.   int             label;
  12.   Symbol         sym;
  13.   int              depth;
  14.   struct sSymbolInfo    *stack, *list;
  15. } SymbolInfo;
  16.  
  17. extern int nextLabelNumber;
  18. extern char *addressToString();
  19. static SymbolInfo *sroot = NULL, *sstack = NULL;
  20. static unsigned int currentDepth = 0;
  21.  
  22. debugStart()
  23. {
  24.   /* lose stuff */
  25.   sstack = NULL;
  26.   sroot = NULL;
  27.   currentDepth = 0;
  28.   TRACE0(debuginfo, 2, "Starting");
  29. }
  30.  
  31. dumpem(s)
  32. register SymbolInfo *s;
  33. {
  34.   char *str;
  35.   int size;
  36.   AllocateKind kind;
  37.   NodePtr ct;
  38.   OID id;
  39.  
  40.   if (s->list) dumpem(s->list);
  41.   switch (s->tag) {
  42.     case DIStart:
  43.       TRACE0(debuginfo, 5, "Start scope");
  44.       writeWord(98);
  45.       emit("\t.long\tL_%d - L_beginCDA\n", s->label);
  46.       break;
  47.     case DIEnd:
  48.       TRACE0(debuginfo, 5, "End scope");
  49.       writeWord(99);
  50.       emit("\t.long\tL_%d - L_beginCDA\n", s->label);
  51.       break;
  52.     case DISymbol:
  53.       TRACE1(debuginfo, 5, "Symbol %s", s->sym->itsName);
  54.       writeWord(100);
  55.       writeWord(strlen(s->sym->itsName));
  56.       writeStringData(s->sym->itsName);
  57.       figureSizeAndKind(s->sym, &size, &kind);
  58.       writeWord(size);
  59.       if (size == 4) {
  60.     extern NodePtr getCTInfo();
  61.     ct = getCTInfo(s->sym);
  62.     if (ct == NULL) {
  63.       Comment("Can't find ct info for %s", s->sym->itsName);
  64.       TRACE1(emit, 0, "Can't find ct info for %s", s->sym->itsName);
  65.       ct = s->sym->value.ATinfo;
  66.       id = OIDOf(ct);
  67.     } else {
  68.       id = ct->b.oblit.codeOID;
  69.     }
  70.       } else {
  71.     ct = s->sym->value.ATinfo;
  72.     id = OIDOf(ct);
  73.       }
  74.       writeHex(id);
  75.       str = addressToString(s->sym->v.address);
  76.       writeWord(strlen(str));
  77.       writeStringData(str);
  78.       break;
  79.     case DIVector:
  80.       TRACE0(debuginfo, 5, "This thing is a vector");
  81.       writeWord(101);
  82.       writeWord(s->label);    /* Really size */
  83.       writeHex((OID)s->sym);    /* Really range AT */
  84.       break;
  85.     default:
  86.       assert(0);
  87.       break;
  88.   }
  89.   free((char *) s);
  90. }
  91.  
  92. debugDump()
  93. {
  94.   /* dump it */
  95.   TRACE0(debuginfo, 2, "Ending");
  96.   emit("L_debugInfoMap:\n");
  97.   if (sroot) dumpem(sroot);
  98.   writeWord(0);
  99.   sroot = sstack = NULL;
  100.   currentDepth = 0;
  101. }
  102.  
  103. static doABegin(tag)
  104. DITag tag;
  105. {
  106.   register SymbolInfo *si;
  107.   si = (SymbolInfo *) malloc(sizeof(SymbolInfo));
  108.   si->tag = tag;
  109.   si->label = nextLabelNumber++;
  110.   emit("L_%d:\n", si->label);
  111.   si->list = sroot;
  112.   sroot = si;
  113. }
  114.  
  115. debugScope(goingin)
  116. int goingin;
  117. {
  118.   SymbolInfo *s;
  119.   if (goingin) {
  120.     currentDepth ++;
  121.     TRACE1(debuginfo, 6, "Begin scope to %d", currentDepth);
  122.     if (currentDepth == 1) doABegin(DIStart);
  123.   } else {
  124.     if (currentDepth == 1 || sstack && sstack->depth == currentDepth) {
  125.       TRACE1(debuginfo, 4, "Back to depth %d", currentDepth-1);
  126.       /* write the stab */
  127.       doABegin(DIEnd);
  128.     }
  129.     while (sstack && sstack->depth == currentDepth) {
  130.       TRACE1(debuginfo, 5, "losing %s", sstack->sym->itsName);
  131.       sstack = sstack->stack;
  132.     }
  133.     currentDepth--;
  134.     TRACE1(debuginfo, 6, "End scope, back to %d", currentDepth);
  135.   }
  136. }
  137.  
  138. debugSymbol(s)
  139. Symbol s;
  140. {
  141.   SymbolInfo *si;
  142.  
  143.   if (StackDepth() < currentDepth) {
  144.     TRACE1(debuginfo, 4, "Up to depth %d", currentDepth);
  145.     /* write the stabs */
  146.     doABegin(DIStart);
  147.   }
  148.   si = (SymbolInfo *) malloc(sizeof(SymbolInfo));
  149.   si->tag = DISymbol;
  150.   si->depth = currentDepth;
  151.   si->sym = s;
  152.   TRACE1(debuginfo, 5, "Adding %s", s->itsName);
  153.   si->stack = sstack;
  154.   sstack = si;
  155.   si->list = sroot;
  156.   sroot = si;
  157. }
  158.  
  159. debugVector(ofAT, size)
  160. OID ofAT;
  161. int size;
  162. {
  163.   SymbolInfo *s;
  164.   TRACE0(debuginfo, 4, "This guy is a vector");
  165.   if (StackDepth() < currentDepth) {
  166.     TRACE1(debuginfo, 4, "Up to depth %d", currentDepth);
  167.     /* write the stabs */
  168.     doABegin(DIStart);
  169.   }
  170.   /* write the stab */
  171.   s = (SymbolInfo *) malloc(sizeof(SymbolInfo));
  172.   s->tag = DIVector;
  173.   s->depth = currentDepth;
  174.   s->label = size;
  175.   s->sym = (Symbol) ofAT;
  176.   s->stack = sstack;
  177.   sstack = s;
  178.   s->list = sroot;
  179.   sroot = s;
  180. }
  181.